package com.zs.factory;

import com.zs.service.Action;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/6/11 上午10:26
 */
public class ActionFactory {

    public static Action createAction(String opr) {
        try {
            Object action;
            return switch (opr) {
                case "login" -> {
                    action = Class.forName("com.zs.service.impl.LoginAction").getDeclaredConstructor().newInstance();
                    yield (Action) action;
                }
                case "logout" -> {
                    action = Class.forName("com.zs.service.impl.LogOutAction").getDeclaredConstructor().newInstance();
                    yield (Action) action;
                }
                default -> throw new RuntimeException("Invalid operation");
            };
        }catch (Exception e){
           throw new RuntimeException(e);
        }
    }
}
